#include<bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;
int T,n,a[N],s[N],res;

void dfs(int u,int sum){
    if(u == n + 1){
        res = max(res,sum);
        return ;
    }
    //color it blue
    int add = 0;
    s[u] = 1;
    for(int i = u - 1;i > 0;i--)
        if(s[i] == 1 && a[i] == a[u]){
            add = a[i];
            break;
        }
    dfs(u + 1,sum + add);

    //color it red
    add = 0;
    s[u] = 2;
    for(int i = u - 1;i > 0;i--)
        if(s[i] == 2 && a[i] == a[u]){
            add = a[i];
            break;
        }
    dfs(u + 1,sum + add);
}

int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);

    scanf("%d",&T);
    while(T--){
        res = 0;
        scanf("%d",&n);
        for(int i = 1;i <= n;i++) scanf("%d",&a[i]);
        dfs(1,0);
        printf("%d\n",res);
    }

    return 0;
}